import sys
sys.path.append("/Users/liyishan/myPythonProjects/python-leetcode")
from node.TreeNode import TreeNode


def rangeSumBST(root: TreeNode, low: int, high: int) -> int:
    if not root:
        return 0
    if root.val > high:
        return rangeSumBST(root.left,low,high)
    if root.val < low:
        return rangeSumBST(root.right,low,high)
    return root.val + rangeSumBST(root.left,low,high) + rangeSumBST(root.right,low,high)


root = TreeNode(10)
root.left = TreeNode(5)
root.right = TreeNode(15)
root.left.left = TreeNode(3)
root.left.right = TreeNode(7)
root.right.right = TreeNode(18)

res = rangeSumBST(root,7,15)
print(res)